<template>
  <div class="buttonAddWrap">
    <el-dialog @opened="$store.commit('dialogTop')" title="新增" :visible.sync="dialogFormVisibleAdd" @close="addDialogClose('ruleFormAdd')">
      <el-form :model="ruleFormAdd" :rules="rulesAdd" ref="ruleFormAdd" label-width="80px" class="demo-ruleForm">
        <el-form-item label="企业" prop="enterpriseNo" :rules="[{ 'required':true, 'message': '请选择企业','trigger': 'blur'  }]">
          <el-select v-model="ruleFormAdd.enterpriseNo" size="mini"  clearable placeholder="请选择企业名称">
            <el-option
              v-for="item in this.$store.state.companyInfos"
              :key="item.enterpriseNo+''"
              :label="item.enterpriseName"
              :value="item.enterpriseNo+''">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发生时间" prop="actionTime" :rules="[{ 'required':true, 'message': '请选择发生时间','trigger': 'blur' }]">
          <el-date-picker
            v-model="ruleFormAdd.actionTime"
            style="width: 100%;"
            align="right"
            type="datetime"
            size="mini"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择日期"
            :picker-options="$store.state.pickerOptions0">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="公示时长" prop="noticeLength" :rules="[{ 'required':true, 'message': '请输入公示时长','trigger': 'blur' }]">
          <el-input clearable size="mini" v-model="ruleFormAdd.noticeLength" type="number" style="width:90%;"
                    auto-complete="off" placeholder="公示时长"></el-input> &nbsp; 天
        </el-form-item>
        <el-form-item label="失信程度" prop="loseLevel" :rules="[{ 'required':true, 'message': '是否严重失信', 'trigger': 'blur'}]">
          <el-radio v-model="ruleFormAdd.loseLevel" :label="0">一般失信</el-radio>
          <el-radio v-model="ruleFormAdd.loseLevel" :label="1">严重失信</el-radio>
        </el-form-item>
        <el-form-item label="行为说明" prop="actionExplain" :rules="[{ 'required':true, 'message': '请输入行为说明', }]">
          <el-input
            type="textarea"
            :rows="3"
            :maxlength="500"
            placeholder="请输入行为说明"
            v-model="ruleFormAdd.actionExplain">
          </el-input>
        </el-form-item>
        <el-form-item label="上传证明" prop="fileId" :rules="[{ 'required':true, 'message': '请上传证明材料', }]">
          <uploadDialog @getfileId="getfileId"></uploadDialog>
       </el-form-item>
        <el-form-item> </el-form-item>
        <div style="text-align: center;margin-bottom: 3px;">
          <el-button type="primary" @click="submitForm('ruleFormAdd')">提交</el-button>
          <el-button @click="dialogFormVisibleAdd = false">取 消</el-button>
        </div>
      </el-form>

    </el-dialog>
  </div>
</template>

<script>
  import uploadDialog from "./uploadDialog.vue"
  export default {
    props:[],
    data () {
      return {
        options1: [{
          value: '1',
          label: '市交通局'
        }, {
          value: '2',
          label: '市交警局'
        }, {
          value: '3',
          label: '市城管局'
        }, {
          value: '4',
          label: '区政府'
        }],
        value6:"",
        ruleFormAdd: {
          "enterpriseNo":"",
          "actionExplain":" ",
          "actionTime":"",
          "noticeLength":"",
          "loseLevel":0,
          "fileId":"",
          "id":"",
        },
        dialogFormVisibleAdd: false,
        rulesAdd: {

        }
      }
    },
    components: {uploadDialog},
    methods: {
      dialogOpen(row){
        for(var i in this.ruleFormAdd){
          this.ruleFormAdd[i]=row[i]
        }
        this.dialogFormVisibleAdd=true
      },
      getfileId(id){
        this.ruleFormAdd.fileId=id
      },
      //关闭回调
      addDialogClose(formName){
        this.$refs[formName].resetFields();
      },
      //提交回调
      handleDiaSureAdd(){

        this.axios.post(process.env.API_HOST + `/credit/updateCreditEnterprise`, this.ruleFormAdd)
          .then(response=>{
            if(response.data.code==200){
              this.$message({
                type: 'success',
                message: '修改成功!'
              });
              this.$emit('searchRowsInfo')
              this.dialogFormVisibleAdd = false
            }

          })
          .catch(error=>{
            console.log(error);
          });
      },

      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.handleDiaSureAdd()
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus" >
  @import "../../../common/stylus/mixin.styl"
  .buttonAddWrap
    display inline-block
    margin-left 10px

</style>
